<?php
if ( !defined('IN_ADMINCP') || !defined('IN_SEC') ){
	exit('Access Denied.');
}
define('UAC_LEVEL', 9);

$id = abs(intval($_G['gp_id']));

if( !$team = fetch('team', $id) ){
	$admincp->cpmsg('项目不存在');
}

if( is_post() ){
	if( !confirm_password($admincp->admin) ){
		$admincp->cpmsg('密码不正确！授权操作失败！');
	}

	$key = $_G['gp_key'] ? htmlspecialchars($_G['gp_key']) : $admincp->cpmsg('请填写项目密钥');

	if( $exists = fetch('team', $key, 'key') ){
		if( $exists['id'] != $team['id'] ){
			$admincp->cpmsg('APPKEY已被使用');
		}
	}

	$secret = $_G['gp_secret'] ? htmlspecialchars($_G['gp_secret']) : '';
	$status = abs(intval($_G['gp_status']));
	$status = $status ? 0 : 1;

	$teamid = $team['id'];
	$update = array(
		'key' => $key,
		'secret' => $secret,
		'status' => $status,
	);
	if( $team ){
		update('team', $team['id'], $update);
		$admincp->log('team', $team['id'], '编辑项目验证：' . $team['name'], $update);
	}
	$admincp->success();
}
?>